package com.zn.opit.tech.easyexcel.exception;

import com.zn.opit.tech.easyexcel.domain.R;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Objects;

@Order(value = 80)
@RestControllerAdvice
public class ExtExceptionHandler {

    @ExceptionHandler(ExtException.class)
    public R handleUnauthorizedException(ExtException e) {
        R error = R.error(e.getCode(), e.getMsg());
        if (Objects.nonNull(e.getData())) {
            error.setData(e.getData());
        }
        return error;
    }
}
